package hash;

import java.util.HashMap;
import java.util.HashSet;
import java.util.logging.Handler;

/*
 *@description 同构字符串
 *@author hkfan
 *@version 1.0
 *@create 2025/6/4 15:48
 */
public class LeetCode_205 {
    public boolean isIsomorphic(String s, String t) {
        //1. 定义map
        HashMap<Character,Character> map = new HashMap<>();
        //2. 循环遍历
        for (int i = 0; i < s.length(); i++) {
            Character a = s.charAt(i);
            Character b = t.charAt(i);
            if (map.containsKey(a)){
                if(map.get(a)!=b){
                    return false;
                }
            }else {
                if (map.containsKey(b) && map.get(b)==b){
                    return false;
                }
                map.put(a,b);
                if(map.keySet().size()!=new HashSet<Character>(map.values()).size()){
                    return false;
                }

            }
        }
        return true;
    }
}
